//
//  WJQViewController5.m
//  TripTogether
//
//  Created by dllo on 15/12/22.
//  Copyright © 2015年 王军岐. All rights reserved.
//

#import "WJQViewController5.h"
#import "CycleScrollView.h"

@interface WJQViewController5 () <UITableViewDataSource, UITableViewDelegate>

@property (nonatomic, strong) UITableView *myTableV;

@property (nonatomic, strong) NSMutableArray *cycleArr;
@property (nonatomic, strong) CycleScrollView *cycleView;

@end

@implementation WJQViewController5

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor redColor];
    
    
    _cycleArr = [NSMutableArray arrayWithObjects:@"http://static.damai.cn/WanEditImg/6eed0a73-d760-4409-aa19-00b9b874713f.jpg",
                 @"http://photos.breadtrip.com/photo_d_2015_12_23_12_48_42_744_123986672_1590611893.jpg?imageView/2/w/960/q/85",
                 @"http://static.damai.cn/WanEditImg/6b368c67-6eca-436e-b2f0-ef0b7dc59f5d.jpg",
                 @"http://static.damai.cn/WanEditImg/0bc1ff45-d6c2-4414-afd8-147ac17c2ef6.jpg",
                 @"http://static.damai.cn/WanEditImg/ee236877-e0ff-49b4-b7d6-bf7dc3e43110.jpg", nil];
    
    
    
    
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"测试" style:UIBarButtonItemStylePlain target:self action:nil];
    
    _myTableV = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - 49 - 64) style:UITableViewStylePlain];
    _myTableV.dataSource = self;
    _myTableV.delegate = self;

    [_myTableV registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
    [self.view addSubview:_myTableV];
    
    // 创建轮播图
    _cycleView = [[CycleScrollView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 180)];
    [_cycleView createCycleScrollViews:_cycleArr];
    _myTableV.tableHeaderView = _cycleView;
    
    // 下拉刷新
    [self addHeaderRefresh];
    [self addFooterRefresh];
    
}
- (void)addHeaderRefresh
{
    _myTableV.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        
        NSLog(@"下拉");
        
        [self getData];
    }];
    // 自动开始下拉刷新
    [_myTableV.mj_header beginRefreshing];
}
- (void)addFooterRefresh
{
    _myTableV.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
       
        NSLog(@"上拉");
        [self getData];
    }];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 20;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    
    cell.textLabel.text = @"测试";
    return cell;
}
- (void)getData
{
    
    NSInteger page = 29;
   NSString *url = [NSString stringWithFormat:@"http://api.breadtrip.com/hunter/products/more/?start=%ld&city_name=上海", page];
    
    [WJQNetwork getAFNet:url block:^(id result) {
        
        NSMutableArray *arr = [result objectForKey:@"product_list"];
        
        
        NSLog(@"第 %ld 页 next_start: %@ -- %ld", page + 20,[result objectForKey:@"next_start"], arr.count);
        
        [_myTableV.mj_header endRefreshing];
        [_myTableV.mj_footer endRefreshing];
        
    } errorBlock:^(NSError *error) {
        
        
    }];

}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
    
    
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
